package com.cjf.demo.spring.jmsdemo;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class MessageSender {

	public static void main(String[] args) {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-jms.xml");
		JmsTemplate template = (JmsTemplate) context.getBean("jmsTemplate");
		Destination destination = (Destination) context.getBean("queue.demo");

		template.send(destination, new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage("Hello, world");
			}
		});
	}
}
